<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=FOwLbScMzZLP0d2qGVvD3stfBYSjwDH4"></script>
    <title>GPS定位</title>
</head>
<body onload="start()">
    <div id="allmap"></div>
</body>
</html>
<script type="text/javascript">

    // 百度地图API功能
    //GPS坐标
    var lon = 113.49362845;
    var lat = 22.23862535;
    var marker;

    function start()
    {
        setPoint();
        getGps();
    }

    function getGps()
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            // IE6, IE5 浏览器执行代码
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                lon = JSON.parse(xmlhttp.responseText).x;
                lat = JSON.parse(xmlhttp.responseText).y;
                <!--alert("get: " + lon + "," + lat);-->
                <!--setTimeout("location.reload();", 5000); // 递归调用-->
                changePoint();
            }
        }
        xmlhttp.open("GET","/gps", true); // 在此处修改文件路径
        xmlhttp.send();
        <!--setPoint();-->
        setTimeout("getGps()", 10000); // 递归调用
    }

    function setPoint()
    {
        var ggPoint = new BMap.Point(lon, lat);

        //地图初始化
        var bm = new BMap.Map("allmap");
        bm.centerAndZoom(ggPoint, 30);
        bm.addControl(new BMap.NavigationControl());

        //坐标转换完之后的回调函数
        translateCallback = function (data){
          if(data.status === 0) {
            marker = new BMap.Marker(data.points[0]);
            bm.addOverlay(marker);
            var label = new BMap.Label(lon + ", " + lat, {offset:new BMap.Size(20,-10)});
            marker.setLabel(label); //添加百度label
            bm.setCenter(data.points[0]);
          }
        }

        var convertor = new BMap.Convertor();
        var pointArr = [];
        pointArr.push(ggPoint);
        convertor.translate(pointArr, 1, 5, translateCallback);
     }

     function changePoint()
     {
        var ggPoint = new BMap.Point(lon, lat);

        tCallback = function (data){
          if(data.status === 0) {
            marker.setPosition(data.points[0]);
            marker.getLabel().setContent(lon + ", " + lat);
            marker.getMap().setCenter(data.points[0]);
          }
        }

        var convertor = new BMap.Convertor();
        var pointArr = [];
        pointArr.push(ggPoint);
        convertor.translate(pointArr, 1, 5, tCallback);
     }

</script>